using NUnit.Framework;
using Tycho.Parser.Peg;

namespace Tycho.Parser.Tests.Peg {
    [TestFixture]
    public class EndOfFileProductionSpecification {
        [Test]
        public void ShouldParseEndOfFile () {
            var eof = new EndOfFileProduction ();

            var result = eof.Parse ("");
            Assert.IsNotNull (result);
            Assert.AreEqual (0, result.Index);
        }

        [Test]
        public void ShouldParseEndOfFileWithWhiteSpaces () {
            var eof = new EndOfFileProduction ();

            var result = eof.Parse (" \t");
            Assert.IsNotNull (result);
            Assert.AreEqual (2, result.Index);
        }

        [Test]
        public void ShouldParseEndOfFileWithNewLines () {
            var eof = new EndOfFileProduction ();

            var result = eof.Parse (" \n\n");
            Assert.IsNotNull (result);
            Assert.AreEqual (3, result.Index);
        }

        [Test]
        public void ShouldParseEndOfFileWithCarriageReturnNewLines () {
            var eof = new EndOfFileProduction ();

            var result = eof.Parse (" \r\n\r\n");
            Assert.IsNotNull (result);
            Assert.AreEqual (5, result.Index);
        }

        [Test]
        public void ShouldNotParseNonWhiteSpaceCharacters () {
            var eof = new EndOfFileProduction ();

            var result = eof.Parse ("d");
            Assert.IsNull (result);
        }

        [Test]
        public void ShouldNotParseSpaceCharactersFollowedByNonWhiteSpaceCharacters () {
            var eof = new EndOfFileProduction ();

            var result = eof.Parse (" d");
            Assert.IsNull (result);
        }

        [Test]
        public void ShouldNotParseNewLineCharactersFollowedByNonWhiteSpace () {
            var eof = new EndOfFileProduction ();

            var result = eof.Parse (" \nd");
            Assert.IsNull (result);
        }
    }
}